package com.domor.xxx.system.service;

import com.domor.xxx.common.core.text.Convert;
import com.domor.xxx.common.utils.AddressUtils;
import com.domor.xxx.system.domain.SysOperLog;
import com.domor.xxx.system.mapper.SysOperLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <h3>操作日志 服务层</h3>
 * @author liyuyang
 * @date 2020/5/6
 **/
@Service
public class SysOperLogService {

    @Autowired
    private SysOperLogMapper operLogMapper;

    /**
     * 查询系统操作日志集合
     * @param operLog 操作日志对象
     * @return 操作日志集合
     */
    public List<SysOperLog> selectOperLogList(SysOperLog operLog) {
        return operLogMapper.selectOperLogList(operLog);
    }

    /**
     * 查询操作日志详细
     * @param operId 操作ID
     * @return 操作日志对象
     */
    public SysOperLog selectOperLogById(Long operId) {
        return operLogMapper.selectOperLogById(operId);
    }

    /**
     * 新增操作日志
     * @param operLog 操作日志对象
     */
    @Async("asyncServiceExecutor")
    public void insertOperlog(SysOperLog operLog) {
        String location = AddressUtils.getRealAddressByIP(operLog.getOperIp());
        operLog.setOperLocation(location);
        operLogMapper.insertOperlog(operLog);
    }

    /**
     * 批量删除系统操作日志
     * @param ids 需要删除的数据
     * @return
     */
    public int deleteOperLogByIds(String ids) {
        return operLogMapper.deleteOperLogByIds(Convert.toStrArray(ids));
    }

    /**
     * 清空操作日志
     */
    public void cleanOperLog() {
        operLogMapper.cleanOperLog();
    }

}
